using System.Xml.Linq;

namespace PocoReport
{
    public class PartFactory
    {
        public static IPart GetPart(XNode node)
        {
            IPart part = null;
            XElement element = node as XElement;
            if(element != null)
            {
                switch (element.Name.ToString())
                {
                    case "Text":
                        part = new Text();
                        break;
                    case "Paragraph":
                        part = new Paragraph();
                        break;
                    case "List":
                        part = new List();
                        break;
                    case "Table":
                        part = new Table();
                        break;
                    case "Image":
                        part = new Image();
                        break;
                    case "Chart":
                        part = new Chart();
                        break;
                }
            }
            else
            {
                XText text = node as XText;
                if(text != null)
                {
                    part = new Content();
                }
            }

            if(part != null)
            {
                part.Load(node);
            }
            return part;
        }
    }
}